/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package idea.model.powersearch;


import idea.model.qnrlibrary.QuestionTitleSearchView;
import java.beans.IntrospectionException;
import java.util.List;
import org.openide.nodes.BeanNode;
import org.openide.nodes.ChildFactory;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import org.openide.util.Exceptions;
import org.openide.util.lookup.Lookups;


/**
 *
 * @author rejun001
 */
public class QTSearchResultsChildFactory extends ChildFactory<QuestionTitleSearchView>
{

    private List<QuestionTitleSearchView> resultList;


    public QTSearchResultsChildFactory( List<QuestionTitleSearchView> resultList )
    {
        this.resultList = resultList;
    }


    @Override
    protected boolean createKeys( List<QuestionTitleSearchView> list )
    {
        list.removeAll( list );
        for ( QuestionTitleSearchView q : resultList )
        {
            list.add( q );
        }
        return true;
    }


    @Override
    protected Node createNodeForKey( QuestionTitleSearchView key )
    {
        QTSearchResultsNode node = null;
        try
        {
            node = new QTSearchResultsNode( key );
        }
        catch ( Exception e )
        {
            Exceptions.printStackTrace( e );
        }
        return node;
    }
    
    private class QTSearchResultsNode extends BeanNode
    {
        private String currSurvey = null;
        private String currRefPeriod = null;
        
        public QTSearchResultsNode( QuestionTitleSearchView bean ) throws IntrospectionException 
        {
            super(bean, Children.LEAF, Lookups.singleton( bean ));
            currSurvey = bean.getSurvey();
            currRefPeriod = bean.getRefPeriod();
            
            setDisplayName( bean.getSurvey() + ": " + bean.getRefPeriod());
            setShortDescription( bean.getCategory() + ": " + bean.getQuestionTitle());
                   
        }
    }
    
    

}
